package main.Q1901_2000;

public class Q1991_2000 {
    public static void main(String[] args) {
        System.out.println("Question1991：找到数组的中间位置");
        System.out.println("Question1992：");
        System.out.println("Question1993：");
        System.out.println("Question1994：");
        System.out.println("Question1995：");
        System.out.println("Question1996：");
        System.out.println("Question1997：");
        System.out.println("Question1998：");
        System.out.println("Question1999：");
        System.out.println("Question2000：");
    }
}

class Question1991{
    public int findMiddleIndex(int[] nums) {
        int middleIndex=-1;
        int[] leftSum=new int[nums.length],rightSum=new int[nums.length];
        if (nums.length!=1){
            for (int i=0;i< nums.length;i++){
                if (i==0) leftSum[i]=nums[i];
                else leftSum[i]=leftSum[i-1]+nums[i];
            }
            for (int j= nums.length-1;j>=0;j--){
                if (j== nums.length-1) rightSum[j]=nums[j];
                else rightSum[j]=rightSum[j+1]+nums[j];
            }
            for (int i=0;i< nums.length;i++){
                if (i==0&&0==rightSum[1]){
                    middleIndex=0;
                    break;
                }else if (i== nums.length-1&&leftSum[nums.length-2]==0){
                    middleIndex= nums.length-1;
                    break;
                }else if (i!=0&&i!= nums.length-1&&leftSum[i-1]==rightSum[i+1]){
                    middleIndex=i;
                    break;
                }
            }
        }else if (nums.length==1) middleIndex=0;
        return middleIndex;
    }
}